package com.sc.byahi.user.client.components;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sc.byahi.user.shared.Profile;

public class ProfileDataCache {
	private Map<Long, Profile> profiles = new HashMap<Long, Profile>();
	private static ProfileDataCache singleton = new ProfileDataCache();

	public static ProfileDataCache get() {
		return singleton;
	}

	public List<Long> getUncachedIds(List<Long> ids) {
		List<Long> unCached = new ArrayList<Long>(ids.size());
		for (Long id : ids) {
			if (!profiles.containsKey(id)) {
				unCached.add(id);
			}
		}
		return unCached;
	}

	public void updateCache(List<Profile> pList) {
		for (Profile p : pList) {
			profiles.put(p.getId(), p);
		}
	}
}
